//Wed Jul 28 13:48:06 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class Islands
{
public:
	int beachLength(vector<string> kingdom)
	{
		int M = kingdom.size();
		int N = kingdom[0].size();
		int count = 0;
		for (int i = 0; i < M; i++)
		{
			for (int j = 0; j < N; j++)
			{
				if (i % 2 == 0)
				{
					if (i - 1 >= 0 && j - 1 >= 0 && kingdom[i][j] != kingdom[i
							- 1][j - 1])
						count++;
					if (j - 1 >= 0 && kingdom[i][j] != kingdom[i][j - 1])
						count++;
					if (i - 1 >= 0 && kingdom[i][j] != kingdom[i - 1][j])
						count++;
				}
				else
				{
					if (i - 1 >= 0 && j + 1 < N && kingdom[i][j] != kingdom[i
							- 1][j + 1])
						count++;
					if (i - 1 >= 0 && kingdom[i][j] != kingdom[i - 1][j])
						count++;
					if (j - 1 >= 0 && kingdom[i][j] != kingdom[i][j - 1])
						count++;
				}
			}
		}
		return count;
	}
};
//Here, the even row and odd row have different situations.
//I just check every situation for each line.
//For the even row, just check the left-up, top and left.
//For the odd row, just check the right-up, top and left.
